﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MetaCollection.Framework;
using MetaCollection.ContentService.Http;

namespace MetaCollection.ContentService.WebDav.Methods
{
	public static class Options
	{
		public static void Respond(DavContext context, IRequestHandler handler)
		{
			Http.HttpMethods supported = context.SupportedMethods;

			if (supported.IsSet(Http.HttpMethods.Get | Http.HttpMethods.Head | Http.HttpMethods.Options | Http.HttpMethods.Put | Http.HttpMethods.PropFind | Http.HttpMethods.PropPatch))
			{
				context.Response.Headers.Add("DAV", "1, 2");
				context.Response.Headers.Add("MS-Author-Via", "DAV");
				context.Response.Headers.Add("Public", supported.ToString().ToUpperInvariant());
			}
			if (supported.IsSet(Http.HttpMethods.VersionControl))
				context.Response.Headers.Add("Versioning-Support", "DAV:basicversioning");
			if (supported.IsSet(Http.HttpMethods.Search))
				context.Response.Headers.Add("DASL", "<DAV:basicsearch>");
			context.Response.Headers.Add("Allow", supported.ToString().ToUpperInvariant());
			context.Response.Headers.Add("Accept-Ranges", "bytes");
			context.Response.StatusCode = (int)SuccessStatus.Ok;
		}
	}
}
